<template>
  <form-item-setting v-model:config="config">
    <a-form-item
      field="defaultValue"
      tooltip=""
      label="默认值"
      :allow-clear="true"
    >
      <a-quarter-picker
        v-model="config.config.defaultValue"
        allow-clear
        position="top"
        popup-container="#ItemSetting"
      />
    </a-form-item>
    <a-form-item
      field="placeholder"
      tooltip=""
      label="提示文字"
    >
      <a-input v-model="config.config.placeholder" allow-clear />
    </a-form-item>
    <a-form-item
      field="position"
      tooltip=""
      label="弹出的位置"
    >
      <a-select v-model="config.config.position" popup-container="#ItemSetting">
        <a-option value="top">top</a-option>
        <a-option value="tl">tl</a-option>
        <a-option value="tr">tr</a-option>
        <a-option value="bottom">bottom</a-option>
        <a-option value="bl">bl</a-option>
        <a-option value="br">br</a-option>
      </a-select>
    </a-form-item>
    <a-form-item
      field="format"
      tooltip=""
      label="日期格式"
    >
      <a-input v-model="config.config.format" allow-clear />
    </a-form-item>
    <a-form-item
      field="allowClear"
      tooltip="是否允许清空输入框"
      label="允许清空"
    >
      <a-switch
        v-model="config.config.allowClear"
        type="round"
      >
        <template #checked>
          允许
        </template>
        <template #unchecked>
          不允许
        </template>
      </a-switch>
    </a-form-item>

    <a-divider style="border-bottom-style: dotted" orientation="center" :size="2" :margin="0">
      事件设置
    </a-divider>
    <br />
    <a-form-item
      field="onChangeFunction"
      tooltip=""
      label="Change"
    >
      <a-button
        type="primary"
        shape="round"
        @click="editOnChange"
      >
        <template #icon>
          <icon-edit />
        </template>
        编辑事件
      </a-button>
      <code-editor
        ref="codeEditorRef"
        v-model:code="config.config.onChangeFunction"
      />
    </a-form-item>
  </form-item-setting>
</template>

<script lang="ts" setup>
import { ref, defineModel } from 'vue';
import FormItemSetting from '@/components/form-design/item-setting/form-item-setting.vue';
import CodeEditor from '@/components/code-editor/index.vue';

const config = defineModel('config');

const codeEditorRef = ref();

const editOnChange = () => {
  codeEditorRef.value.open();
};

</script>

<script lang="ts">
export default {
  name: 'ItemSettingQuarterPicker'
};
</script>

<style scoped>

</style>